//
//  HMEmotionManager.swift
//  EmotionKeybaord
//
//  Created by ZhuDong on 16/5/31.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class HMEmotionManager: NSObject {
    static let shareManager = HMEmotionManager()
    var packages:[HMEmotionPackage] = [HMEmotionPackage]()
    override init() {
        super.init()
        self.loadEmotionsPath()
    }
    func loadEmotionsPath(){
        let path = NSBundle.mainBundle().pathForResource("emoticons.plist", ofType: nil, inDirectory: "Emoticons.bundle")!
        let dict = NSDictionary(contentsOfFile: path) as! [String:AnyObject]
        let array = dict["packages"] as! [[String:AnyObject]]
        for item in array {
            let id = item["id"] as! String
            loadEmotionsInfo(id)
        }
        
    }
    func loadEmotionsInfo(id: String){
        let emotionPath = "Emoticons.bundle/" + id
        let emotionsInfoPath = NSBundle.mainBundle().pathForResource("info.plist", ofType: nil, inDirectory: emotionPath)
        let emotionsInfo = NSDictionary(contentsOfFile: emotionsInfoPath!)!
        let title = emotionsInfo["group_name_cn"] as! String
        let array = emotionsInfo["emoticons"] as! [[String:AnyObject]]
        let package = HMEmotionPackage(id: id, title: title, emotions: array)
        packages.append(package)
    }
}
